<?php
class admin_listController extends adminController{

    //首页
    public function index() {
        //TAG分类
        $this->class_list=model('tags_category')->tags_category_list();
        $this->show();  
    }

    //AJAX获取内容列表
    public function ajax_content_list()
    {
        //分页参数
        $listRows=20;
        $page = intval($_POST['page']);
        $limit_start = ($page - 1) * $listRows;
        $limit = $limit_start . ',' . $listRows;

        //列表信息
        $list=model('tags')->tags_list($limit,$where['where']);
        $count=model('tags')->count($where['where']);

        //总页数
        $countpage=ceil($count/$listRows);

        if(!empty($list)){
            foreach ($list as $vo) {
                $html.='
                <tr id="del_'.$vo['id'].'">
                    <td><input name="id[]" type="checkbox" id="id[]" value="'.$vo['id'].'" ></td>
                    <td>'.$vo['id'].'</td>
                    <td >'.$vo['name'].'</td>
                    <td>';
                if($vo['cname']){
                    $html.=$vo['cname'];
                }else{
                    $html.='未归类';
                }
                $html.='</td>
                    <td>'.$vo['quote'].'</td>
                    <td >'.$vo['click'].'</td>
                </tr>
                ';
            }
            $status=1;
        }else{
            $html='<tr><td colspan="7"><center>暂无查找到内容<center></td></tr>';
            $status=0;
        }

        @header("Content-type:text/html");
        echo json_encode(array('status' => $status, 'info' => $html ,'countpage'=>$countpage));
    }

    //批量操作
    public function batch(){
        if(empty($_POST['status'])||empty($_POST['id'])){
            $this->msg('操作无效！',0);
        }
        $id_array=substr($_POST['id'],0,-1);
        $id_array=explode(',', $id_array);
        if(empty($id_array)){
            $this->msg('请先选择TAG！',0);
        }
        switch ($_POST['status']) {
            case '1':
                //删除
                foreach ($id_array as $value) {
                    model('tags')->del($value);
                }
                break;
            case '2':
                //转移栏目
                $cid=intval($_POST['cid']);
                if(empty($cid)){
                    $this->msg('请先选择目标栏目！',0);
                }
                foreach ($id_array as $value) {
                    $data=array();
                    $data['id']=$value;
                    $data['cid']=$cid;
                    model('tags')->edit($data);
                }
                break;
        }
        $this->msg('操作执行完毕！',1);

    }


}